#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstring>
#include <cerrno>
using namespace std;

#define  PATH "./fifo" 

class Fifo
{
public:
    Fifo(const string& s = PATH)
        :_pathName(PATH)
    {
        int n = mkfifo(_pathName.c_str(), 0666);
        if(n == 0)
        {
            cout << "mkfifo success" << endl;
        }
        else if(n < 0)
        {
            cout << "mkfifo filed, errno: " << errno << ", error_string: " << strerror(errno) << endl;
        }
    }

    ~Fifo()
    {
        int n = unlink(_pathName.c_str());
        if(n == 0)
        {
            cout << "unlink success" << endl;
        }
        else
        {
            cout << "unlinkq filed, errno: " << errno << ", error_string: " << strerror(errno) << endl;
        }
    }
    
private:
    string _pathName;
};